package com.ophiux.FeverManagement.api.portImpl;

import java.lang.reflect.Type;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.gson.reflect.TypeToken;
import com.ophiux.FeverManagement.api.port.getWechatInfoPort;
import com.ophiux.FeverManagement.aplication.bean.wechat.getWechatInfoRequest;
import com.ophiux.FeverManagement.aplication.bean.wechat.getWechatInfoResponse;
import com.ophiux.FeverManagement.aplication.service.wechat.IGetWechatInfoService;
import com.ophiux.micro.core.application.Request;
import com.ophiux.micro.core.application.Result;
import com.ophiux.micro.core.application.ResultEnum;
import com.ophiux.utils.parser.json.JsonUtils;
import com.ophiux.utils.parser.json.JsonUtils.TypeObtainCallback;

import lombok.extern.slf4j.Slf4j;
@Service
@Slf4j
public class getWechatInfoPortImpl implements getWechatInfoPort{
	@Autowired
	IGetWechatInfoService getWechatInfoService;

	@Override
	public String getWechatInfo(String data) {
		log.info("getWechatInfo请求参数:---->"+data);
		Result<getWechatInfoResponse> result = null;
		Request<getWechatInfoRequest> request = null;
		try {
			request = JsonUtils.toEntity(data, new TypeObtainCallback() {
				public Type getObtainType() {
					return new TypeToken<Request<getWechatInfoRequest>>() {
					}.getType();
				}
			});
			
			result = getWechatInfoService.getWechatInfo(request.getPARAM());
			
		} catch (Exception e) {
			e.printStackTrace();
			log.info("getWechatInfo接口异常：",e);
			result = Result.fail(ResultEnum.requestException);
		}
		log.info("getWechatInfo接口,请求参数："+data+"\n getWechatInfo接口,返回参数："+ result.toJson());
		return result.toJson();
	}

}
